function init() {
	var b = $("toggleBtn");
	var c = $("pinAll");
	var g = chrome.i18n.getMessage("toggleBtnText");
	var h = $("captureWebpageItem");
	var a = $("captureWindowItem");
	var f = $("captureAreaItem");
	var e = $("preferences");
	h.getElementsByTagName("span")[0].innerHTML = chrome.i18n
			.getMessage("captureWebpage");
	a.getElementsByTagName("span")[0].innerHTML = chrome.i18n
			.getMessage("captureWindow");
	f.getElementsByTagName("span")[0].innerHTML = chrome.i18n
			.getMessage("captureArea");
	e.innerHTML = e.title = chrome.i18n.getMessage("preferences");
	c.getElementsByTagName("span")[0].innerHTML = chrome.i18n
			.getMessage("pinText");
	$("extName").innerHTML = chrome.i18n.getMessage("extName");
	$("about").innerHTML = $("about").title = chrome.i18n.getMessage("about");
	$("extName").addEventListener("click", function() {
		open_href("http://www.juximao.com/")
	});
	$("preferences").addEventListener("click", function() {
		open_href("/preferences.html")
	});
	$("about").addEventListener("click", function() {
		open_href("http://www.juximao.com/about/")
	});
	var j = document.querySelectorAll("#menu .capture");
	for ( var d = 0; d < j.length; d++) {
		if (!j[d].classList.contains("disabled")) {
			j[d].classList.add("disabled")
		}
	}
	b.addEventListener("click", function() {
		chrome.extension.sendRequest({
			msg : "toggle"
		}, function(i) {
			var k = i.isToggleOn;
			var l = b.getElementsByTagName("span")[0];
			l.setAttribute("class", k ? "checked" : "unchecked")
		});
		chrome.extension.sendRequest({
			msg : "ga",
			type : "popup item",
			value : "toggleBtn"
		}, function() {
		})
	});
	c.addEventListener("click", function() {
		if (this.classList.contains("disabled")) {
			return false
		}
		chrome.tabs.getSelected(null, function(i) {
			var k = i.url;
			k = k.replace(/^https?:\/\/(www)?/, "");
			if (k.indexOf(DOMAIN) == 0) {
				return
			}
			chrome.tabs.sendRequest(i.id, {
				msg : "showValidImages"
			}, function(l) {
			})
		});
		chrome.extension.sendRequest({
			msg : "ga",
			type : "popup item",
			value : "pinAll"
		}, function() {
		});
		setTimeout(function() {
			window.close()
		}, 100)
	});
	h.addEventListener("click", function() {
		if (this.classList.contains("disabled")) {
			return false
		}
		chrome.extension.sendRequest({
			msg : "ga",
			type : "popup item",
			value : "captureWebpage"
		}, function() {
		});
		var i = chrome.extension.getBackgroundPage();
		i.screenshot.captureWebpage();
		window.close()
	});
	a.addEventListener("click", function() {
		if (this.classList.contains("disabled")) {
			return false
		}
		chrome.extension.sendRequest({
			msg : "ga",
			type : "popup item",
			value : "captureWindow"
		}, function() {
		});
		var i = chrome.extension.getBackgroundPage();
		i.screenshot.captureWindow();
		window.close()
	});
	f.addEventListener("click", function() {
		if (this.classList.contains("disabled")) {
			return false
		}
		chrome.extension.sendRequest({
			msg : "ga",
			type : "popup item",
			value : "captureArea"
		}, function() {
		});
		var i = chrome.extension.getBackgroundPage();
		i.screenshot.showSelectionArea();
		window.close()
	});
	chrome.extension.sendRequest({
		msg : "isToggleOn"
	}, function(i) {
		var k = i.isToggleOn;
		var l = b.getElementsByTagName("span")[0];
		l.innerHTML = g;
		l.setAttribute("class", k ? "checked" : "unchecked")
	});
	chrome.tabs.getSelected(null, function(i) {
		chrome.tabs.sendRequest(i.id, {
			msg : "is_page_capturable"
		}, function(k) {
			if (k.msg == "capturable") {
				$("captureWindowItem").classList.remove("disabled");
				$("captureAreaItem").classList.remove("disabled");
				$("captureWebpageItem").classList.remove("disabled")
			} else {
				$("captureWindowItem").classList.add("disabled");
				$("captureAreaItem").classList.add("disabled");
				$("captureWebpageItem").classList.add("disabled")
			}
		});
		chrome.tabs.sendRequest(i.id, {
			msg : "is_page_pinable"
		}, function(k) {
			if (k.msg == "pinable") {
				$("pinAll").classList.remove("disabled")
			} else {
				$("pinAll").classList.add("disabled")
			}
		})
	});
	chrome.tabs.executeScript(null, {
		file : "js/isload.js"
	})
}
document.addEventListener("DOMContentLoaded", init);
chrome.extension.onRequest.addListener(function(c, b, a) {
	if (c.msg == "page_capturable") {
		$("captureWindowItem").classList.remove("disabled");
		$("captureAreaItem").classList.remove("disabled");
		$("captureWebpageItem").classList.remove("disabled")
	} else {
		if (c.msg == "page_uncapturable") {
			$("captureWindowItem").classList.add("disabled");
			$("captureAreaItem").classList.add("disabled");
			$("captureWebpageItem").classList.add("disabled")
		}
	}
});
function resizeDivWidth(b, a) {
	$(b).style.width = a + "px"
}
function open_href(a) {
	window.open(a)
};